package avicit.cbb.techclass.billdefine.action.service.impl;

import avicit.cbb.businessclass.fondsmanage.action.DBConnectionCustomManager;
import avicit.cbb.fondsmanage.service.CbbFondsDbIntfsService;
import avicit.cbb.techclass.billdefine.action.service.BillDefineManagerService;
import avicit.cbb.techclass.billdefine.domain.CbbTabForm;
import avicit.cbb.techclass.billdefine.domain.CbbTabFormConfig;
import avicit.cbb.techclass.billdefine.domain.CbbTabFormNode;
import avicit.cbb.techclass.billdefine.service.BillDefineManagerService;
import avicit.cbb.techclass.tabledefine.commtablemanager.dao.CommTableManagerDao;
import avicit.cbb.techclass.tabledefine.commtablemanager.domain.CbbTabColumns;
import avicit.cbb.techclass.tabledefine.commtablemanager.action.service.CommTableManagerService;
import avicit.cbb.techclass.tabledefine.commtempletmanager.domain.CbbTempletCode;
import avicit.platform6.api.sysuser.SysDeptAPI;
import avicit.platform6.api.sysuser.SysUserAPI;
import avicit.platform6.commons.utils.ComUtil;
import avicit.platform6.commons.utils.PojoUtil;
import avicit.platform6.core.dao.Paging;
import avicit.platform6.core.domain.BeanBase;
import avicit.platform6.core.exception.DaoException;
import avicit.platform6.core.jdbc.JdbcAvicit;
import avicit.platform6.core.jdbc.Page;
import avicit.platform6.core.properties.PlatformConstant.OpResult;
import avicit.platform6.core.properties.PlatformConstant.OpType;
import avicit.platform6.core.service.ServiceBase;

import avicit.platform6.modules.system.syslog.service.LogBaseFactory;
import avicit.platform6.modules.system.syslog.service.SysLogUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.cxf.common.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 金航数码科技有限责任公司
 * </p>
 * <p>
 * 作者：朱锋
 * </p>
 * <p>
 * 邮箱：zhufeng@avicit.com
 * </p>
 * <p>
 * 创建时间： 2014-9-29 下午6:16:04
 * </p>
 * <p>
 * 类说明：表单实现类
 * </p>
 * <p>
 * 修改记录：
 * </p>
 */
@Service
@SuppressWarnings("unchecked")
public class BillDefineManagerServiceImpl extends ServiceBase implements BillDefineManagerService {

	@Autowired(required = false)
	private JdbcAvicit jdbcAvicit;
	@Autowired(required = true)
	CommTableManagerDao commTableManagerDao;
	@Autowired
	private CommTableManagerService commTableManagerService;
	@Autowired(required = false)
	CbbFondsDbIntfsService cbbFondsDbIntfsService;

	@Autowired
	private SysUserAPI userLoader;
	@Autowired
	private SysDeptAPI deptLoader;

	@Override
	public void delete(BeanBase arg0) throws DaoException {
		// TODO Auto-generated method stub

	}

	@Override
	public void insert(BeanBase arg0) throws DaoException {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(BeanBase arg0) throws DaoException {
		// TODO Auto-generated method stub

	}

	/**
	 * 获取列代码信息
	 *
	 * @author 朱锋
	 * @param page
	 * @param parameter
	 * @param orgId
	 * @return Page<Map<String,Object>>
	 * @throws
	 */
	@Override
	public Page<Map<String, Object>> getPageBillDetailList(Paging<CbbTempletCode> page, Map<String, Object> parameter, String orgId) {
		String sysId = (String) parameter.get("sysId");
		String nodeId = (String) parameter.get("nodeId");
		String tableId = commTableManagerService.getTableIdBysnId(sysId, nodeId);// tableId
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.ID,\n");
		sbSql.append("       T.COL_LABEL,\n");
		sbSql.append("       T.COL_NAME,\n");
		sbSql.append("       T.COL_TYPE,\n");
		sbSql.append("       T.COL_LENGTH,\n");
		sbSql.append("       T.COL_IS_MUST,\n");
		sbSql.append("       CTFC.FORM_VERTICAL,\n");
		sbSql.append("       CTFC.FORM_HORIZONTAL,\n");
		sbSql.append("       T.REMARK\n");
		sbSql.append("  FROM CBB_TAB_COLUMNS T\n");
		sbSql.append("  LEFT JOIN CBB_TAB_FORM_CONFIG CTFC\n");
		sbSql.append("    ON T.ID = CTFC.COLUMN_ID\n");
		sbSql.append(" WHERE T.TABLE_ID = '" + tableId + "'\n");
		Page<Map<String, Object>> pageBean = new Page<Map<String, Object>>(page.getPageNo(), page.getPageSize());
		jdbcAvicit.getDatesByPageForMap(pageBean, sbSql.toString(), parameter, null);
		return pageBean;
	}

	/**
	 * 创建表单信息 参数：系统标识ID，节点ID，节点名称，库表ID
	 *
	 * @author 朱锋
	 * @param sysId
	 * @param nodeName
	 * @param orgId
	 * @param deptId
	 * @param tableId
	 * @param nodeId
	 * @param json
	 * @throws Exception
	 *             void
	 * @throws
	 */
	@Override
	public void createCbbTabForm(String sysId, String nodeName, String orgId, String deptId, String tableId, String nodeId, String json) throws Exception {
		// 1.给tabForm表新增记录
		String formId = ComUtil.getId();
		CbbTabForm cbbTabForm = new CbbTabForm();
		cbbTabForm.setId(formId);
		cbbTabForm.setFormName(nodeName + "_表单");
		cbbTabForm.setFormIsDefalt("Y");
		cbbTabForm.setOrgId(orgId);
		cbbTabForm.setDeptId(deptId);
		cbbTabForm.setSysId(sysId);
		PojoUtil.setSysProperties(cbbTabForm, OpType.insert);
		hibernateDao.save(cbbTabForm);
		SysLogUtil.log(cbbTabForm, null, OpType.insert, OpResult.success);
		// 2.给CBB_TAB_FORM_CONFIG表新增记录
		// String templetId = getTempletId(orgId, sysId.toUpperCase());// templetId
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.ID,T.COL_ORDER\n");
		sbSql.append("  FROM CBB_TAB_COLUMNS T\n");
		sbSql.append(" WHERE T.TABLE_ID = '" + tableId + "'\n");
		List<Object[]> objList = hibernateDao.findBySQL(sbSql.toString());
		for (int i = 0; i < objList.size(); i++) {
			String columnId = String.valueOf(objList.get(i)[0]);// 列ID
			String colOrder = String.valueOf(objList.get(i)[1]);// 列顺序
			CbbTabFormConfig cbbTabFormConfig = new CbbTabFormConfig();
			BigDecimal formv = new BigDecimal(Integer.parseInt("1"));
			BigDecimal formh = new BigDecimal(Integer.parseInt("1"));
			cbbTabFormConfig.setId(ComUtil.getId());
			cbbTabFormConfig.setFormId(formId);
			cbbTabFormConfig.setColumnId(columnId);
			cbbTabFormConfig.setFormVertical(formv);
			cbbTabFormConfig.setFormHorizontal(formh);
			BigDecimal colOrderb = new BigDecimal(Integer.parseInt(colOrder));
			cbbTabFormConfig.setAttribute11(colOrderb);
			cbbTabFormConfig.setOrgId(orgId);
			cbbTabFormConfig.setSysId(sysId);
			cbbTabFormConfig.setDeptId(deptId);
			JSONArray ja = JSONArray.fromObject(json);
			for (int j = 0; j < ja.size(); j++) {
				JSONObject jj = JSONObject.fromObject(ja.get(j));
				String cid = jj.getString("ID");
				if (cid.equals(columnId)) {
					String formVertical = jj.getString("FORM_VERTICAL");
					String formHorizontal = jj.getString("FORM_HORIZONTAL");
					formv = new BigDecimal(Integer.parseInt(formVertical));
					formh = new BigDecimal(Integer.parseInt(formHorizontal));
					cbbTabFormConfig.setFormVertical(formv);
					cbbTabFormConfig.setFormHorizontal(formh);
				}
			}
			PojoUtil.setSysProperties(cbbTabFormConfig, OpType.insert);
			hibernateDao.save(cbbTabFormConfig);
			SysLogUtil.log(cbbTabFormConfig, null, OpType.insert, OpResult.success);
		}
		// 3.给获取记录ID
		String tabNodeId = commTableManagerService.getCbbTabNodeId(sysId, nodeId, tableId);
		// 4.给CBB_TAB_FORM_NODE新增记录
		String formNodeId = ComUtil.getId();
		CbbTabFormNode cbbTabFormNode = new CbbTabFormNode();
		cbbTabFormNode.setId(formNodeId);
		cbbTabFormNode.setTabNodeId(tabNodeId);
		cbbTabFormNode.setFormId(formId);
		cbbTabFormNode.setOrgId(orgId);
		cbbTabFormNode.setDeptId(deptId);
		cbbTabFormNode.setSysId(sysId);
		PojoUtil.setSysProperties(cbbTabFormNode, OpType.insert);
		hibernateDao.save(cbbTabFormNode);
		SysLogUtil.log(cbbTabFormNode, null, OpType.insert, OpResult.success);
	}

	/**
	 * 创建档案类型表单信息 参数：系统标识ID，节点ID，节点名称，库表ID，档案状态类型archiveStatus
	 *
	 * @author 唐坤
	 * @param sysId
	 * @param nodeName
	 * @param orgId
	 * @param deptId
	 * @param tableId
	 * @param nodeId
	 * @param json
	 * @throws Exception
	 *             void
	 * @throws
	 */
	@Override
	public void createCbbTabForm(String sysId, String nodeName, String orgId, String deptId, String tableId, String nodeId, String json, String archiveStatus) throws Exception {
		    String formId = ComUtil.getId();
			CbbTabForm cbbTabForm = new CbbTabForm();
			cbbTabForm.setId(formId);
			cbbTabForm.setFormName(nodeName + "_表单"+archiveStatus);
			cbbTabForm.setFormIsDefalt("Y");
			cbbTabForm.setOrgId(orgId);
			cbbTabForm.setDeptId(deptId);
			cbbTabForm.setSysId(sysId);
			cbbTabForm.setArchiveStatus(archiveStatus);
			PojoUtil.setSysProperties(cbbTabForm, OpType.insert);
			hibernateDao.save(cbbTabForm);
			SysLogUtil.log(cbbTabForm, null, OpType.insert, OpResult.success);
		// 2.给CBB_TAB_FORM_CONFIG表新增记录
		// String templetId = getTempletId(orgId, sysId.toUpperCase());// templetId
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.ID,T.COL_ORDER,T.ATTRIBUTE_11,T.COL_IS_DETAIL,T.COL_IS_MUST,T.COL_IS_TAB_VISIBLE,T.COL_IS_VISIBLE\n");
		sbSql.append("  FROM CBB_TAB_COLUMNS T\n");
		sbSql.append(" WHERE T.TABLE_ID = '" + tableId + "'\n");
		sbSql.append(" and T.COL_IS_DISPLAY = 'Y' ");
		List<Object[]> objList = hibernateDao.findBySQL(sbSql.toString());
		for (int i = 0; i < objList.size(); i++) {
			String columnId = String.valueOf(objList.get(i)[0]);// 列ID
			String colOrderde = String.valueOf(objList.get(i)[1]);// 表单顺序
			String colTabOrderde = String.valueOf(objList.get(i)[2]);// 表格顺序
			String colIsDetailde = String.valueOf(objList.get(i)[3]);//是否详细显示
			String colIsMustde = String.valueOf(objList.get(i)[4]);//是否必著
			String colIsTabVisiblede = String.valueOf(objList.get(i)[5]);//是否表格显示
			String colIsVisiblede = String.valueOf(objList.get(i)[6]);//是否添加/编辑显示

			CbbTabFormConfig cbbTabFormConfig = new CbbTabFormConfig();
			BigDecimal formv = new BigDecimal(Integer.parseInt("1"));
			BigDecimal formh = new BigDecimal(Integer.parseInt("1"));
			BigDecimal colOrderbde = new BigDecimal(Integer.parseInt(colOrderde));
			cbbTabFormConfig.setAttribute11(colOrderbde);
			try {
				BigDecimal colTabOrderbde = new BigDecimal(Integer.parseInt(colTabOrderde));
				cbbTabFormConfig.setAttribute12(colTabOrderbde);
			} catch (NumberFormatException e) {
				//SanXiaFiles update by huangjian 2019-08-14 如果不是数字，是空 个默认值  colOrderbde
				cbbTabFormConfig.setAttribute12(colOrderbde);
			}
			cbbTabFormConfig.setColIsDetail(colIsDetailde);//是否详细显示
			cbbTabFormConfig.setAttribute01(colIsMustde);//是否必著
			cbbTabFormConfig.setAttribute02(colIsTabVisiblede);//是否表格显示
			cbbTabFormConfig.setAttribute03(colIsVisiblede);//是否添加/编辑显示
			cbbTabFormConfig.setId(ComUtil.getId());
			cbbTabFormConfig.setFormId(formId);
			cbbTabFormConfig.setColumnId(columnId);
			cbbTabFormConfig.setFormVertical(formv);
			cbbTabFormConfig.setFormHorizontal(formh);
			cbbTabFormConfig.setOrgId(orgId);
			cbbTabFormConfig.setSysId(sysId);
			cbbTabFormConfig.setDeptId(deptId);
			JSONArray ja = JSONArray.fromObject(json);
			data:for (int j = 0; j < ja.size(); j++) {
				JSONObject jj = JSONObject.fromObject(ja.get(j));
				String cid = jj.getString("ID");
				if (cid.equals(columnId)) {
					String formVertical = jj.getString("FORM_VERTICAL");
					String formHorizontal = jj.getString("FORM_HORIZONTAL");
					String colIsMust = jj.getString("COL_IS_MUST");
					String colIsDetail = jj.getString("COL_IS_DETAIL");
					String colIsVisible = jj.getString("COL_IS_VISIBLE");
					String colIsTabVisible = jj.getString("COL_IS_TAB_VISIBLE");
					String colOrder = jj.getString("COL_ORDER");
					String colTabOrder = jj.getString("ATTRIBUTE_12");
					formv = new BigDecimal(Integer.parseInt(formVertical));
					formh = new BigDecimal(Integer.parseInt(formHorizontal));
					cbbTabFormConfig.setFormVertical(formv);
					cbbTabFormConfig.setFormHorizontal(formh);
					cbbTabFormConfig.setColIsDetail(colIsDetail);//是否详细显示
					cbbTabFormConfig.setAttribute01(colIsMust);//是否必著
					cbbTabFormConfig.setAttribute02(colIsTabVisible);//是否表格显示
					cbbTabFormConfig.setAttribute03(colIsVisible);//是否添加/编辑显示
					BigDecimal colOrderb = new BigDecimal(Integer.parseInt(colOrder));
					cbbTabFormConfig.setAttribute11(colOrderb);
					BigDecimal colTabOrderb = new BigDecimal(Integer.parseInt(colTabOrder));
					cbbTabFormConfig.setAttribute12(colTabOrderb);
					break data;
				}
			}
			PojoUtil.setSysProperties(cbbTabFormConfig, OpType.insert);
			hibernateDao.save(cbbTabFormConfig);
			SysLogUtil.log(cbbTabFormConfig, null, OpType.insert, OpResult.success);
		}
		// 3.给获取记录ID
		String tabNodeId = commTableManagerService.getCbbTabNodeId(sysId, nodeId, tableId);
		// 4.给CBB_TAB_FORM_NODE新增记录
		String formNodeId = ComUtil.getId();
		CbbTabFormNode cbbTabFormNode = new CbbTabFormNode();
		cbbTabFormNode.setId(formNodeId);
		cbbTabFormNode.setTabNodeId(tabNodeId);
		cbbTabFormNode.setFormId(formId);
		cbbTabFormNode.setOrgId(orgId);
		cbbTabFormNode.setDeptId(deptId);
		cbbTabFormNode.setSysId(sysId);
		cbbTabFormNode.setArchiveStatus(archiveStatus);
		PojoUtil.setSysProperties(cbbTabFormNode, OpType.insert);
		hibernateDao.save(cbbTabFormNode);
		SysLogUtil.log(cbbTabFormNode, null, OpType.insert, OpResult.success);
	}

	/**
	 * 根据表单配置ID获取该对象
	 *
	 * @author 朱锋
	 * @param id
	 * @return CbbTabFormConfig
	 * @throws
	 */
	@Override
	public CbbTabFormConfig getcbbTabFormConfigById(String id) {
		CbbTabFormConfig h = (CbbTabFormConfig) hibernateDao.getSession().get(CbbTabFormConfig.class, id);
		return h;
	}

	/**
	 * 更新表单配置表信息
	 *
	 * @author 朱锋
	 * @param cbbTabFormConfig
	 *            void
	 * @throws
	 */
	@Override
	public void updateCbbTabForm(CbbTabFormConfig cbbTabFormConfig) throws Exception{
		CbbTabFormConfig objOld = getcbbTabFormConfigById(cbbTabFormConfig.getId());
		hibernateDao.evict(objOld);
		CbbTabFormConfig newBean = new CbbTabFormConfig();
		PojoUtil.copyProperties(newBean, objOld, true);
		PojoUtil.copyProperties(newBean, cbbTabFormConfig, true);
		SysLogUtil.log(newBean, objOld, OpType.update, OpResult.success);
		PojoUtil.setSysProperties(newBean, OpType.update);
		hibernateDao.update(newBean);
	}

	/**
	 * 根据CID 获取FormConfig主键ID
	 *
	 * @author 朱锋
	 * @param cid
	 * @return String
	 * @throws
	 */
	/**
	 * 根据CID 获取FormConfig主键ID
	 */
	@Override
	public String getCbbTabFormConfigByCid(String cid) {
		String formConfig = "";
		String sql = "SELECT T.ID FROM CBB_TAB_FORM_CONFIG T WHERE T.COLUMN_ID = '" + cid + "'";
		List<Object> objList = hibernateDao.findBySQL(sql);
		if (objList != null && objList.size() != 0) {
			formConfig = String.valueOf(objList.get(0));
		}
		return formConfig;
	}

	/**
	 * 获取列信息对象集合
	 *
	 * @author 朱锋
	 * @param tableId
	 * @param flag
	 *            （1-添加显示；2-列表显示；3-详细显示；4-查询显示）
	 * @return List<CbbTabColumns>
	 * @throws
	 */
	@Override
	public List<CbbTabColumns> getFormShowList(String tableId, String flag) {
		List<CbbTabColumns> cbbTabColumnsList = new ArrayList<CbbTabColumns>();
		String sql = "SELECT T.ID FROM CBB_TAB_COLUMNS T WHERE T.TABLE_ID ='" + tableId + "' ORDER BY T.COL_ORDER,T.COL_NAME";
		List<Object> objList = hibernateDao.findBySQL(sql);
		for (int i = 0; i < objList.size(); i++) {
			String cid = String.valueOf(objList.get(i));
			CbbTabColumns cbbTabColumns = new CbbTabColumns();
			cbbTabColumns = commTableManagerService.getCbbTabColumnsById(cid);
			cbbTabColumns.setColName(cbbTabColumns.getColName().toUpperCase());
			if ("Y".equals(cbbTabColumns.getColIsDisplay())) {
				if ("1".equals(flag)) {
					if ("Y".equals(cbbTabColumns.getColIsVisible())) {
						cbbTabColumnsList.add(cbbTabColumns);
					}
				} else if ("2".equals(flag)) {
					if ("Y".equals(cbbTabColumns.getColIsTabVisible())) {
						cbbTabColumnsList.add(cbbTabColumns);
					}
				} else if ("3".equals(flag)) {
					if ("Y".equals(cbbTabColumns.getColIsVisible())) {
						cbbTabColumnsList.add(cbbTabColumns);
					}
				} else if ("4".equals(flag)) {
					if ("Y".equals(cbbTabColumns.getColIsSearch())) {
						cbbTabColumnsList.add(cbbTabColumns);
					}
				}
			}
		}
		return cbbTabColumnsList;
	}

	/**
	 * 通过TABLEID取得列信息表格显示对象集合
	 *
	 * @author 朱锋
	 * @param tableId
	 * @param id
	 * @param tableName
	 * @param flag
	 * @param sysId
	 * @param orgId
	 * @param deptId
	 * @return
	 * @throws Exception
	 *             List<CbbTabColumns>
	 * @throws
	 */
	@Override
	public List<CbbTabColumns> getFormShowTableList(String tableId, String id, String tableName, String flag, String sysId, String orgId, String deptId) throws Exception {
		// flag 1-是否添加或编辑显示 2-是否列表显示 3-是否详细显示 4-是否查询显示
		List<CbbTabColumns> cbbTabColumnsList = new ArrayList<CbbTabColumns>();
		String sql = "SELECT T.ID FROM CBB_TAB_COLUMNS T WHERE T.TABLE_ID ='" + tableId + "' ORDER BY T.COL_ORDER,T.COL_NAME";
		List<Object> objList = hibernateDao.findBySQL(sql);
		// 连接池
		DBConnectionCustomManager connectionMan = null;
		String poolName = orgId + "_" + sysId;
		Connection conn = null;
		Statement statement = null;
		ResultSet rs = null;
		// 实例化连接池
		connectionMan = DBConnectionCustomManager.getInstance(poolName);
		// 获取连接
		conn = connectionMan.getConnection(poolName);// 根据连接池名称从连接池中获取连接
		statement = conn.createStatement();
		try {
			for (int i = 0; i < objList.size(); i++) {
				String cdata = "";// 数据字符串
				String cid = String.valueOf(objList.get(i));
				CbbTabColumns cbbTabColumns = new CbbTabColumns();
				cbbTabColumns = commTableManagerService.getCbbTabColumnsById(cid);
				cbbTabColumns.setColName(cbbTabColumns.getColName().toUpperCase());
				StringBuffer sbSql = new StringBuffer();
				sbSql.append("SELECT " + cbbTabColumns.getColName().toUpperCase() + " FROM " + tableName.toUpperCase() + " WHERE ID = '" + id + "'");
				rs = statement.executeQuery(sbSql.toString());
				while (rs.next()) {
					cdata = cdata + rs.getString(cbbTabColumns.getColName().toUpperCase()) + ",";
				}
				if (!"".equals(cdata)) {
					cdata = cdata.substring(0, cdata.length() - 1);
				}
				// 给colValueName字段充数据值----user&&dept&&custom
				if ("user".equals(cbbTabColumns.getColRuleName())) {
					if (!"".equals(cdata)) {
						String[] users = cdata.split(",");
						String usersName = "";
						for (int q = 0; q < users.length; q++) {
							if (!"".equals(users[q]) && null != users[q] && !"null".equals(users[q])) {
								usersName = usersName + userLoader.getSysUserById(users[q]).getName() + ",";
							}
						}
						if (!"".equals(usersName)) {
							usersName = usersName.substring(0, usersName.length() - 1);
						}
						cbbTabColumns.setColValueName(usersName);
					}
				} else if ("dept".equals(cbbTabColumns.getColRuleName())) {
					if (!"".equals(cdata)) {
						String[] depts = cdata.split(",");
						String deptName = "";
						for (int q = 0; q < depts.length; q++) {
							if (!"".equals(depts[q]) && null != depts[q]) {
								deptName = deptName + deptLoader.getSysDeptTl(depts[q], "zh_CN").getDeptName() + ",";
							}
						}
						if (!"".equals(deptName)) {
							deptName = deptName.substring(0, deptName.length() - 1);
						}
						cbbTabColumns.setColValueName(deptName);
					}
				} else if ("custom".equals(cbbTabColumns.getColRuleName())) {
					if (!"".equals(cdata)) {
						String path = cbbTabColumns.getCustomPath();// 获取自定义页面路径
						// 截取表名，字段值
						if (!"".equals(path) && null != path) {
							String[] url = path.split("[?]");
							if (url.length > 1) {
								String[] arg = url[1].split("&");// 表名，字段值字符串
								if (arg.length > 1) {
									String cNames = "";// 返回的显示值字符串
									String tName = arg[0].split("=")[1];// 表名
									String cName = arg[1].split("=")[1];// 列名
									// JDBC实现
									// 查询列的值，并且给colValueName赋值
									ResultSet rss = null;
									Statement statements = null;
									StringBuffer sbSqlCustom = new StringBuffer();
									sbSqlCustom.append("SELECT T." + cName + "\n");
									sbSqlCustom.append("  FROM " + tName + " T\n");
									sbSqlCustom.append(" WHERE T.ID IN (");
									String[] datas = cdata.split(",");
									for (int d = 0; d < datas.length; d++) {
										if (d == datas.length - 1) {
											sbSqlCustom.append("'" + datas[d] + "'\n");
										} else {
											sbSqlCustom.append("'" + datas[d] + "',\n");
										}
									}
									sbSqlCustom.append(")");
									try {
										statements = conn.createStatement();
										rss = statements.executeQuery(sbSqlCustom.toString());
										while (rss.next()) {
											cNames = cNames + rss.getString(cName) + ",";
										}
										if (!"".equals(cNames)) {
											cNames = cNames.substring(0, cNames.length() - 1);
										}
										cbbTabColumns.setColValueName(cNames);
									} catch (Exception e) {
										e.printStackTrace();
									} finally {
										if (rss != null) {
											try {
												rss.close();
											} catch (Exception e) {
												e.printStackTrace();
											}
										}
										if (statements != null) {
											try {
												statements.close();
											} catch (Exception e) {
												e.printStackTrace();
											}
										}
									}
								}
							}
						}
					}
				}
				cbbTabColumns.setColValue(cdata);
				if (cbbTabColumns.getColValueName() == null) {
					cbbTabColumns.setColValueName("");
				}
				if ("1".equals(flag)) {
					if ("Y".equals(cbbTabColumns.getColIsVisible())) {
						cbbTabColumnsList.add(cbbTabColumns);
					}
				} else if ("2".equals(flag)) {
					if ("Y".equals(cbbTabColumns.getColIsTabVisible())) {
						cbbTabColumnsList.add(cbbTabColumns);
					}
				} else if ("3".equals(flag)) {
					if ("Y".equals(cbbTabColumns.getColIsDetail())) {
						cbbTabColumnsList.add(cbbTabColumns);
					}
				} else if ("4".equals(flag)) {
					if ("Y".equals(cbbTabColumns.getColIsSearch())) {
						cbbTabColumnsList.add(cbbTabColumns);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			if (conn != null) {
				try {
					connectionMan.deleteConnection(poolName, conn);// 释放，但并未断开连接
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		return cbbTabColumnsList;
	}

	/**
	 * 通过TABLEID取得列信息表格显示对象集合(只用于添加页面)
	 *
	 * @author 朱锋
	 * @param tableId
	 * @param id
	 * @param tableName
	 * @param flag
	 * @param sysId
	 * @param orgId
	 * @param deptId
	 * @return
	 * @throws Exception
	 *             List<CbbTabColumns>
	 * @throws
	 */
	@Override
	public List<CbbTabColumns> getFormShowTableListToAdd(String tableId, String id, String tableName, String flag, String sysId, String orgId, String deptId, String selectedId) throws Exception {
		// flag 1-是否添加或编辑显示 2-是否列表显示 3-是否详细显示 4-是否查询显示
		List<CbbTabColumns> cbbTabColumnsList = new ArrayList<CbbTabColumns>();
		String sql = "SELECT T.ID FROM CBB_TAB_COLUMNS T WHERE T.TABLE_ID ='" + tableId + "' ORDER BY T.COL_ORDER,T.COL_NAME";
		List<Object> objList = hibernateDao.findBySQL(sql);
		// 连接池
		DBConnectionCustomManager connectionMan = null;
		String poolName = orgId + "_" + sysId;
		Connection conn = null;
		Statement statement = null;
		ResultSet rs = null;
		// 实例化连接池
		connectionMan = DBConnectionCustomManager.getInstance(poolName);
		// 获取连接
		conn = connectionMan.getConnection(poolName);// 根据连接池名称从连接池中获取连接
		statement = conn.createStatement();
		try {
			for (int i = 0; i < objList.size(); i++) {

				String cid = String.valueOf(objList.get(i));
				CbbTabColumns cbbTabColumns = new CbbTabColumns();
				cbbTabColumns = commTableManagerService.getCbbTabColumnsById(cid);
				cbbTabColumns.setColName(cbbTabColumns.getColName().toUpperCase());
				String cdata = "";
				StringBuffer sbSql = new StringBuffer();
				sbSql.append("SELECT " + cbbTabColumns.getColName().toUpperCase() + " FROM " + tableName.toUpperCase() + " WHERE ID = '" + id + "'");
				rs = statement.executeQuery(sbSql.toString());
				while (rs.next()) {
					cdata = cdata + rs.getString(cbbTabColumns.getColName().toUpperCase()) + ",";
				}
				if (!"".equals(cdata)) {
					cdata = cdata.substring(0, cdata.length() - 1);
				}
				// 给colValueName字段充数据值----user&&dept&&custom
				if ("user".equals(cbbTabColumns.getColRuleName())) {
					if (!"".equals(cdata)) {
						String[] users = cdata.split(",");
						String usersName = "";
						for (int q = 0; q < users.length; q++) {
							if (!"".equals(users[q]) && null != users[q] && !"null".equals(users[q])) {
								usersName = usersName + userLoader.getSysUserById(users[q]).getName() + ",";
							}
						}
						if (!"".equals(usersName)) {
							usersName = usersName.substring(0, usersName.length() - 1);
						}
						cbbTabColumns.setColValueName(usersName);
					}
				} else if ("dept".equals(cbbTabColumns.getColRuleName())) {
					if (!"".equals(cdata)) {
						String[] depts = cdata.split(",");
						String deptName = "";
						for (int q = 0; q < depts.length; q++) {
							if (!"".equals(depts[q]) && null != depts[q]) {
								deptName = deptName + deptLoader.getSysDeptTl(depts[q], "zh_CN").getDeptName() + ",";
							}
						}
						if (!"".equals(deptName)) {
							deptName = deptName.substring(0, deptName.length() - 1);
						}
						cbbTabColumns.setColValueName(deptName);
					}
				} else if ("custom".equals(cbbTabColumns.getColRuleName())) {
					if (!"".equals(cdata)) {
						String path = cbbTabColumns.getCustomPath();// 获取自定义页面路径
						// 截取表名，字段值
						if (!"".equals(path) && null != path) {
							String[] url = path.split("[?]");
							if (url.length > 1) {
								String[] arg = url[1].split("&");// 表名，字段值字符串
								if (arg.length > 1) {
									String cNames = "";// 返回的显示值字符串
									String tName = arg[0].split("=")[1];// 表名
									String cName = arg[1].split("=")[1];// 列名
									// JDBC实现
									// 查询列的值，并且给colValueName赋值
									ResultSet rss = null;
									Statement statements = null;
									StringBuffer sbSqlCustom = new StringBuffer();
									sbSqlCustom.append("SELECT T." + cName + "\n");
									sbSqlCustom.append("  FROM " + tName + " T\n");
									sbSqlCustom.append(" WHERE T.ID IN (");
									String[] datas = cdata.split(",");
									for (int d = 0; d < datas.length; d++) {
										if (d == datas.length - 1) {
											sbSqlCustom.append("'" + datas[d] + "'\n");
										} else {
											sbSqlCustom.append("'" + datas[d] + "',\n");
										}
									}
									sbSqlCustom.append(")");
									try {
										statements = conn.createStatement();
										rss = statements.executeQuery(sbSqlCustom.toString());
										while (rss.next()) {
											cNames = cNames + rss.getString(cName) + ",";
										}
										if (!"".equals(cNames)) {
											cNames = cNames.substring(0, cNames.length() - 1);
										}
										cbbTabColumns.setColValueName(cNames);
									} catch (Exception e) {
										e.printStackTrace();
									} finally {
										if (rss != null) {
											try {
												rss.close();
											} catch (Exception e) {
												e.printStackTrace();
											}
										}
										if (statements != null) {
											try {
												statements.close();
											} catch (Exception e) {
												e.printStackTrace();
											}
										}
									}

								}
							}
						}
					}
				}
				// 获取字段默认值s
				String geneMethod = cbbTabColumns.getColGeneMethod();
				String colDropdownType = cbbTabColumns.getColDropdownType();
				String colType = cbbTabColumns.getColType();
				String colGeneMethodRule = cbbTabColumns.getColGeneMethodRule();
				String colRuleName = cbbTabColumns.getColRuleName();
				if ("".equals(selectedId)) { // 第一次添加数据
					if ("1".equals(geneMethod)) { // 默认值
						if ("1".equals(colDropdownType) || "2".equals(colDropdownType)) { // 通用代码
							cdata = colGeneMethodRule;
						} else if ("3".equals(colDropdownType)) {
							cdata = colGeneMethodRule;// 将id赋给隐藏域
							if ("user".equals(colRuleName)) { // 选人默认值
								// 根据colGeneMethodRule查出userName，绑定在colValueName下
								String userName = this.getUserNameById(colGeneMethodRule);
								cbbTabColumns.setColValueName(userName);
							} else if ("dept".equals(colRuleName)) { // 选部门默认值
								// 根据colGeneMethodRule查出deptName，绑定在colValueName下
								String deptName = this.getDeptNameById(colGeneMethodRule);
								cbbTabColumns.setColValueName(deptName);
							} else if ("custom".equals(colRuleName)) { // 自定义选择页默认值
								// 根据colGeneMethodRule查出sysName，绑定在colValueName下
								String sysName = this.getSysNameByCode(colGeneMethodRule);
								cbbTabColumns.setColValueName(sysName);
							}
						} else if ("0".equals(colDropdownType)) { // 普通字段
							cdata = colGeneMethodRule;
						}
					} else if ("2".equals(geneMethod)) { // 序列;
						if ("1".equals(colDropdownType)) { // 参选
							// 将colGeneMethodRule设置给colValue
							cdata = "";
							cbbTabColumns.setColValueName(cdata);
						} else if ("0".equals(colDropdownType)) { // 普通字段
							if ("string".equals(colType)) {
								cdata = "";
							} else if ("integer".equals(colType)) {
								cdata = "";
							} else if ("float".equals(colType)) {
								cdata = "";
							} else if ("clob".equals(colType)) {
								cdata = "";
							}
						}
					} else if ("3".equals(geneMethod)) { // 顺带
						cdata = "";
						if ("3".equals(colDropdownType)) {
							if ("user".equals(colRuleName)) { // 选人
								cbbTabColumns.setColValueName(cdata);
							} else if ("dept".equals(colRuleName)) { // 选部门
								cbbTabColumns.setColValueName(cdata);
							} else if ("custom".equals(colRuleName)) { // 自定义选择
								cbbTabColumns.setColValueName(cdata);
							}
						}
					}
					// else if ("4".equals(geneMethod)) { // 组合项
					//
					// } else if ("5".equals(geneMethod)) { // 统计生成
					//
					// }
				} else { // 选择一行数据时添加
							// 根据选中数据的ID获取对象
					String sqlSelected = "SELECT * FROM CBB_CS_WJ T WHERE T.ID = '" + selectedId + "'";
					List<Map<String, Object>> list = this.jdbcAvicit.queryForMap(sqlSelected, null);
					Map<String, Object> selectedObjectMap = new HashMap<String, Object>();
					if (list.size() > 0) {
						selectedObjectMap = list.get(0);
					}
					if ("1".equals(geneMethod)) { // 默认值
						if ("1".equals(colDropdownType) || "2".equals(colDropdownType)) { // 通用代码
							cdata = colGeneMethodRule;
						} else if ("3".equals(colDropdownType)) {
							cdata = colGeneMethodRule;// 将id赋给隐藏域
							if ("user".equals(colRuleName)) { // 选人默认值
								// 根据colGeneMethodRule查出userName，绑定在colValueName下
								String userName = this.getUserNameById(colGeneMethodRule);
								cbbTabColumns.setColValueName(userName);
							} else if ("dept".equals(colRuleName)) { // 选部门默认值
								// 根据colGeneMethodRule查出deptName，绑定在colValueName下
								String deptName = this.getDeptNameById(colGeneMethodRule);
								cbbTabColumns.setColValueName(deptName);
							} else if ("custom".equals(colRuleName)) { // 自定义选择页默认值
								// 根据colGeneMethodRule查出sysName，绑定在colValueName下
								String sysName = this.getSysNameByCode(colGeneMethodRule);
								cbbTabColumns.setColValueName(sysName);
							}
						} else if ("0".equals(colDropdownType)) { // 普通字段
							cdata = colGeneMethodRule;
						}
					} else if ("2".equals(geneMethod)) { // 序列;将选中数据的值和序列的值根据字段类型拼接
						// 选中数据字段对应值
						String selectedValue = (String) selectedObjectMap.get(cbbTabColumns.getColName());
						if ("1".equals(colDropdownType)) { // 参选
							// 将colGeneMethodRule设置给colValue
							cdata = selectedValue + colGeneMethodRule;
							cbbTabColumns.setColValueName(cdata);
						} else if ("0".equals(colDropdownType)) { // 普通字段
							if ("string".equals(colType)) {
								cdata = stringConfig(selectedValue, colGeneMethodRule);
							} else if ("integer".equals(colType)) {
								int cdataInteger = Integer.parseInt(selectedValue) + Integer.parseInt(colGeneMethodRule);
								cdata = String.valueOf(cdataInteger);
							} else if ("float".equals(colType)) {
								float cdataFloat = Float.parseFloat(selectedValue) + Float.parseFloat(colGeneMethodRule);
								cdata = String.valueOf(cdataFloat);
							} else if ("clob".equals(colType)) {
								cdata = selectedValue + colGeneMethodRule;
							}
						}
					} else if ("3".equals(geneMethod)) { // 顺带
						// 将选中数据的值赋给colValue，根据字段名获取数据对象的值
						cdata = (String) selectedObjectMap.get(cbbTabColumns.getColName());
						if ("3".equals(colDropdownType)) {
							if ("user".equals(colRuleName)) { // 选人
								// 根据colGeneMethodRule查出userName，绑定在colValueName下
								String userName = this.getUserNameById(cdata);
								cbbTabColumns.setColValueName(userName);
							} else if ("dept".equals(colRuleName)) { // 选部门
								// 根据colGeneMethodRule查出deptName，绑定在colValueName下
								String deptName = this.getDeptNameById(cdata);
								cbbTabColumns.setColValueName(deptName);
							} else if ("custom".equals(colRuleName)) { // 自定义选择
								// 根据colGeneMethodRule查出sysName，绑定在colValueName下
								String sysName = this.getSysNameByCode(cdata);
								cbbTabColumns.setColValueName(sysName);
							}
						}
					} else if ("4".equals(geneMethod)) { // 组合项
						String sourceId = cbbTabColumns.getId();// 源字段ID
						String recordId = "";// CBB项目中没有其它表，所以给空字符串
						Map<String, Map<String, Map<String, String>>> map = this.getConfigMap(sourceId, tableId, recordId);
						cbbTabColumns.setGroupMap(map);
					}
					// else if ("5".equals(geneMethod)) { // 统计生成
					//
					// }
				}
				// 给colValue字段充数据值
				cbbTabColumns.setColValue(cdata);
				if (cbbTabColumns.getColValueName() == null) {
					cbbTabColumns.setColValueName("");
				}
				if ("1".equals(flag)) {
					if ("Y".equals(cbbTabColumns.getColIsVisible())) {
						cbbTabColumnsList.add(cbbTabColumns);
					}
				} else if ("2".equals(flag)) {
					if ("Y".equals(cbbTabColumns.getColIsTabVisible())) {
						cbbTabColumnsList.add(cbbTabColumns);
					}
				} else if ("3".equals(flag)) {
					if ("Y".equals(cbbTabColumns.getColIsDetail())) {
						cbbTabColumnsList.add(cbbTabColumns);
					}
				} else if ("4".equals(flag)) {
					if ("Y".equals(cbbTabColumns.getColIsSearch())) {
						cbbTabColumnsList.add(cbbTabColumns);
					}
				}
			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			if (conn != null) {
				try {
					connectionMan.deleteConnection(poolName, conn);// 释放，但并未断开连接
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}

		return cbbTabColumnsList;
	}

	/**
	 * 获取基本字段生成方式为通用代码的字段集合
	 */
	@Override
	public Map<String, Map<String, String>> getRuleCodeList(List<CbbTabColumns> list, String flag, String sysId, String orgId) {
		// flag 1-是否添加或编辑显示 2-是否列表显示 3-是否详细显示 4-是否查询显示
		Map<String, Map<String, String>> mapCode = new HashMap<String, Map<String, String>>();
		// 循环基本字段
		for (int i = 0; i < list.size(); i++) {
			CbbTabColumns cbbTabColumns = list.get(i);
			// 判断该字段是否存在通用代码
			if ("1".equals(cbbTabColumns.getColDropdownType()) || "2".equals(cbbTabColumns.getColDropdownType())) {
				StringBuffer sbSql = new StringBuffer();
				sbSql.append("SELECT CTCC.LOOKUP_NAME, CTCC.LOOKUP_CODE\n");
				sbSql.append("  FROM CBB_TAB_COL_CODE CTCC\n");
				sbSql.append(" WHERE CTCC.COLUMN_ID = '" + cbbTabColumns.getId() + "' AND CTCC.CODE_IS_VALID = 'Y'\n");
				sbSql.append("UNION\n");
				sbSql.append("SELECT CLV.LOOKUP_NAME, CLV.LOOKUP_CODE\n");
				sbSql.append("  FROM CBB_TAB_COL_SYS_CODE CTCSC\n");
				sbSql.append("  LEFT JOIN CBB_LOOKUP_V CLV\n");
				sbSql.append("    ON CLV.ID = CTCSC.SYS_LOOKUP_ID\n");
				sbSql.append(" WHERE CTCSC.COLUMN_ID = '" + cbbTabColumns.getId() + "'");
				List<Object[]> colCodeList = hibernateDao.findBySQL(sbSql.toString());
				String colValue = cbbTabColumns.getColValue();// 字段具体的值
				int num = 0;
				for (int j = 0; j < colCodeList.size(); j++) {
					String lookupCode = String.valueOf(colCodeList.get(j)[1]);// 真实值
					if (lookupCode.equals(colValue)) {
						num++;
					}
				}
				if (num == 0) {
					Object[] obj = {colValue, colValue};
					colCodeList.add(obj);
				}
				Map<String, String> map = new HashMap<String, String>();
				for (int j = 0; j < colCodeList.size(); j++) {
					String lookupName = String.valueOf(colCodeList.get(j)[0]);// 显示值
					String lookupCode = String.valueOf(colCodeList.get(j)[1]);// 真实值
					if (null == lookupName) {
						lookupName = lookupCode;
					}
					map.put(lookupCode, lookupName);
				}
				if ("1".equals(flag)) {
					if ("Y".equals(cbbTabColumns.getColIsVisible())) {
						mapCode.put(cbbTabColumns.getColName(), map);
					}
				} else if ("2".equals(flag)) {
					if ("Y".equals(cbbTabColumns.getColIsTabVisible())) {
						mapCode.put(cbbTabColumns.getColName(), map);
					}
				} else if ("3".equals(flag)) {
					if ("Y".equals(cbbTabColumns.getColIsDetail())) {
						mapCode.put(cbbTabColumns.getColName(), map);
					}
				} else if ("4".equals(flag)) {
					if ("Y".equals(cbbTabColumns.getColIsSearch())) {
						mapCode.put(cbbTabColumns.getColName(), map);
					}
				}
			}
		}
		return mapCode;
	}

	/**
	 * 获取部门用户字符串
	 */
	@Override
	public String getUserDpetString(String tableId, String sysId, String orgId) throws Exception {
		// flag 1-是否添加或编辑显示 2-是否列表显示 3-是否详细显示 4-是否查询显示
		String userDpetString = "";
		String sql = "SELECT T.ID FROM CBB_TAB_COLUMNS T WHERE T.TABLE_ID ='" + tableId + "' ORDER BY T.COL_ORDER,T.COL_NAME";
		List<Object> colList = hibernateDao.findBySQL(sql);
		// 循环基本字段
		for (int i = 0; i < colList.size(); i++) {
			String cid = String.valueOf(colList.get(i));
			CbbTabColumns cbbTabColumns = new CbbTabColumns();
			cbbTabColumns = commTableManagerService.getCbbTabColumnsById(cid);
			if ("user".equals(cbbTabColumns.getColRuleName())) {
				userDpetString = userDpetString + "user," + cbbTabColumns.getColName() + "," + cbbTabColumns.getColName() + "NAME,选择用户;";
			} else if ("dept".equals(cbbTabColumns.getColRuleName())) {
				userDpetString = userDpetString + "dept," + cbbTabColumns.getColName() + "," + cbbTabColumns.getColName() + "NAME,选择部门;";
			}
		}
		return userDpetString;
	}

	/**
	 * 获取列数据源
	 *
	 * @author 朱锋
	 * @param page
	 * @param parameter
	 * @param orgId
	 * @param deptId
	 * @return
	 * @throws Exception
	 *             Page<Map<String,Object>>
	 * @throws
	 */
	@Override
	public Page<Map<String, Object>> getPageCodeDetailList(Paging<CbbTabColumns> page, Map<String, Object> parameter, String orgId, String deptId) throws Exception {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		String sysId = (String) parameter.get("sysId");
		String nodeId = (String) parameter.get("nodeId");
		String tableName = (String) parameter.get("tableName");
		tableName = tableName.toUpperCase();
		String tableId = commTableManagerService.getTableIdBysnId(sysId, nodeId);
		String sql = "SELECT * FROM " + tableName + " WHERE 1=1";
		String jsonData = (String) parameter.get("jsonData");
		if (jsonData != null) {
			JSONArray ja = JSONArray.fromObject(jsonData);
			for (int i = 0; i < ja.size(); i++) {
				JSONObject jj = JSONObject.fromObject(ja.get(i));
				String name = jj.getString("name");
				String value = jj.getString("value");
				if (!value.equals("")) {
					String type = getColType(tableName, name, sysId, nodeId, orgId);// 获取该字段类型
					if (type.equals("string")) {
						sql = sql + " AND " + name + "='" + value + "'";
					} else if (type.equals("integer")) {
						sql = sql + " AND " + name + "=" + value;
					} else if (type.equals("date")) {
						sql = sql + " AND " + name + "= TO_DATE('" + value + "','yyyy-MM-dd HH24:mi:ss')";
					} else if (type.equals("float")) {
						sql = sql + " AND " + name + "=" + value;
					} else if (type.equals("float")) {
						sql = sql + " AND " + name + "='" + value + "'";
					}
				}
			}
		}
		// JDBC实现
		Page<Map<String, Object>> pageBean = new Page<Map<String, Object>>(page.getPageNo(), page.getPageSize());
		List<CbbTabColumns> formShowList = getFormShowTableList(tableId, "", tableName, "2", sysId, orgId, deptId);// 基本字段对象
		String sqlPage = "";
		String sqlCount = "select count(1) from (" + sql + ")";
		long count = 0;
		int firstResult = pageBean.getFirstEntityIndex();
		int maxResults = pageBean.getRows();
		if (firstResult <= 0) {
			sqlPage = "select * from ( " + sql + " ) where rownum <= " + maxResults;
		} else {
			sqlPage = "select * from ( select row_.*, rownum rownum_var from ( " + sql + " ) row_ where rownum <= " + (firstResult + maxResults) + ") where rownum_var > " + firstResult;
		}
		// 连接池
		DBConnectionCustomManager connectionMan = null;
		String poolName = orgId + "_" + sysId;
		Connection conn = null;
		Statement statement = null;
		ResultSet rs = null;
		try {
			// 实例化连接池
			connectionMan = DBConnectionCustomManager.getInstance(poolName);
			// 获取连接
			conn = connectionMan.getConnection(poolName);// 根据连接池名称从连接池中获取连接
			statement = conn.createStatement();
			rs = statement.executeQuery(sqlCount);
			while (rs.next()) {
				count = rs.getLong(1);
			}
			rs = statement.executeQuery(sqlPage);
			while (rs.next()) {
				Map<String, Object> map = new HashMap<String, Object>();
				// 循环基本字段进行赋值
				for (int i = 0; i < formShowList.size(); i++) {
					String cValue = "";// 具体的值
					String colName = formShowList.get(i).getColName();// 列名
					if ("string".equals(formShowList.get(i).getColType())) {
						cValue = rs.getString(colName);
						cValue = "null".equals(cValue) ? "" : cValue;
					} else if ("integer".equals(formShowList.get(i).getColType())) {
						cValue = rs.getString(colName);
						cValue = "null".equals(cValue) ? "" : cValue;
					} else if ("date".equals(formShowList.get(i).getColType())) {
						cValue = rs.getDate(colName) + "";
						cValue = "null".equals(cValue) ? "" : cValue;
					} else if ("float".equals(formShowList.get(i).getColType())) {
						cValue = rs.getString(colName);
						cValue = "null".equals(cValue) ? "" : cValue;
					} else if ("clob".equals(formShowList.get(i).getColType())) {
						cValue = rs.getString(colName);
						cValue = "null".equals(cValue) ? "" : cValue;
					}
					if ("1".equals(formShowList.get(i).getColDropdownType()) || "2".equals(formShowList.get(i).getColDropdownType())) {
						StringBuffer sbSql = new StringBuffer();
						sbSql.append("SELECT T.LOOKUP_NAME\n");
						sbSql.append("  FROM CBB_TAB_LOOKUP_V T\n");
						sbSql.append(" WHERE T.COLUMN_ID = '" + formShowList.get(i).getId() + "'\n");
						sbSql.append("   AND T.LOOKUP_CODE = '" + cValue + "'");
						List<Object> listValue = hibernateDao.findBySQL(sbSql.toString());
						String codeName = "";
						if (listValue.size() != 0) {
							codeName = String.valueOf(listValue.get(0));// 获取该列该值所对应的通用代码名称
						} else {
							codeName = cValue;
						}
						map.put(colName, codeName);
					} else if ("user".equals(formShowList.get(i).getColRuleName())) {
						if (!"".equals(cValue) && null != cValue && !"null".equals(cValue)) {
							String[] users = cValue.split(",");
							String usersName = "";
							for (int q = 0; q < users.length; q++) {
								if (!"".equals(users[q]) && null != users[q]) {
									usersName = usersName + userLoader.getSysUserById(users[q]).getName() + ",";
								}
							}
							usersName = usersName.substring(0, usersName.length() - 1);
							map.put(colName, usersName);
						}
					} else if ("dept".equals(formShowList.get(i).getColRuleName())) {
						if (!"".equals(cValue) && null != cValue && !"null".equals(cValue)) {
							String[] depts = cValue.split(",");
							String deptName = "";
							for (int q = 0; q < depts.length; q++) {
								if (!"".equals(depts[q]) && null != depts[q]) {
									deptName = deptName + deptLoader.getSysDeptTl(depts[q], "zh_CN").getDeptName() + ",";
								}
							}
							deptName = deptName.substring(0, deptName.length() - 1);
							map.put(colName, deptName);
						}
					} else if ("custom".equals(formShowList.get(i).getColRuleName())) {
						if (!"".equals(cValue) && null != cValue && !"null".equals(cValue)) {
							String path = formShowList.get(i).getCustomPath();// 获取自定义页面路径
							// 截取表名，字段值
							if (!"".equals(path) && null != path) {
								String[] url = path.split("[?]");
								if (url.length > 1) {
									String[] arg = url[1].split("&");// 表名，字段值字符串
									if (arg.length > 1) {
										String cNames = "";// 返回的显示值字符串
										String tName = arg[0].split("=")[1];// 表名
										String cName = arg[1].split("=")[1];// 列名
										StringBuffer sbSqlCustom = new StringBuffer();
										sbSqlCustom.append("SELECT T." + cName + "\n");
										sbSqlCustom.append("  FROM " + tName + " T\n");
										sbSqlCustom.append(" WHERE T.ID IN (");
										String[] datas = cValue.split(",");
										for (int d = 0; d < datas.length; d++) {
											if (d == datas.length - 1) {
												sbSqlCustom.append("'" + datas[d] + "'\n");
											} else {
												sbSqlCustom.append("'" + datas[d] + "',\n");
											}
										}
										sbSqlCustom.append(")");
										// JDBC实现
										Statement statements = null;
										ResultSet rss = null;
										try {
											statements = conn.createStatement();
											rss = statements.executeQuery(sbSqlCustom.toString());
											while (rss.next()) {
												cNames = cNames + rss.getString(cName) + ",";
											}
											if (!"".equals(cNames) && null != cNames && !"null".equals(cNames)) {
												cNames = cNames.substring(0, cNames.length() - 1);
											}
											map.put(colName, cNames);
										} catch (Exception e) {
											e.printStackTrace();
											throw new Exception("数据库操作异常，请联系管理员！");
										} finally {
											if (rss != null) {
												try {
													rss.close();
													rss = null;
												} catch (Exception e) {
													e.printStackTrace();
												}
											}
											if (statements != null) {
												try {
													statements.close();
													statements = null;
												} catch (Exception e) {
													e.printStackTrace();
												}
											}
										}
									}
								}
							}
						}
					} else {
						map.put(colName, cValue);
					}
				}
				map.put("ID", rs.getString("ID"));
				list.add(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			if (conn != null) {
				try {
					connectionMan.deleteConnection(poolName, conn);// 释放，但并未断开连接
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		pageBean.setEntities(list);
		pageBean.setEntityCount(count);
		return pageBean;
	}

	/**
	 * 通过表名，字段名称,系统标识获取字段类型
	 */
	public String getColType(String tableName, String colNamem, String sysId, String nodeId, String orgId) {
		String type = "";
		// String templetId = getTempletId(orgId, sysId.toUpperCase());// templetId
		String tableId = commTableManagerService.getTableIdBysnId(sysId, nodeId);
		String sql = "SELECT T.COL_TYPE\n" + "  FROM CBB_TAB_COLUMNS T\n" + " WHERE T.TABLE_ID = '" + tableId + "'\n" + "   AND T.COL_NAME = '" + colNamem + "'\n";
		List<Object> objList = hibernateDao.findBySQL(sql);
		if (objList.size() != 0) {
			type = String.valueOf(objList.get(0));// 字段类型
		}
		return type;
	}

	/**
	 * 表单数据新增方法
	 *
	 * @param json
	 * @param sysId
	 * @param tableName
	 * @param nodeName
	 * @param nodeId
	 */
	@Override
	public void insertFormData(String json, String sysId, String tableName, String nodeName, String nodeId, String orgId, String deptId, String loginUserId, String loginIp) throws Exception {
		tableName = tableName.toUpperCase();
		String sql = "INSERT INTO " + tableName + "(ID,";
		if (json != null) {
			JSONArray ja = JSONArray.fromObject(json);
			for (int i = 0; i < ja.size(); i++) {
				JSONObject jj = JSONObject.fromObject(ja.get(i));
				String name = jj.getString("name");
				String type = getColType(tableName, name, sysId, nodeId, orgId);// 获取该字段类型
				if (type.equals("integer")) {
					String value = jj.getString("value");
					if (!"".equals(value)) {
						sql = sql + name + ",";
					}
				} else {
					sql = sql + name + ",";
				}
			}
			sql = sql + "LAST_UPDATE_DATE,LAST_UPDATED_BY,CREATION_DATE,CREATED_BY,LAST_UPDATE_IP,VERSION) VALUES ('" + ComUtil.getId() + "',";
			for (int i = 0; i < ja.size(); i++) {
				JSONObject jj = JSONObject.fromObject(ja.get(i));
				String name = jj.getString("name");
				String value = jj.getString("value");
				String type = getColType(tableName, name, sysId, nodeId, orgId);// 获取该字段类型
				if (type.equals("string")) {
					sql = sql + "'" + value + "',";
				} else if (type.equals("integer")) {
					if (!"".equals(value)) {
						sql = sql + value + ",";
					}
				} else if (type.equals("date")) {
					sql = sql + "TO_DATE('" + value + "','yyyy-MM-dd HH24:mi:ss'),";
				} else if (type.equals("float")) {
					if (!"".equals(value)) {
						sql = sql + value + ",";
					}
				} else if (type.equals("clob")) {
					if (!"".equals(value)) {
						sql = sql + "'" + value + "',";
					}
				}
			}
			sql = sql + "SYSDATE," + loginUserId + ",SYSDATE," + loginUserId + ",'" + loginIp + "',1)";
			// JDBC实现
			executeJdbc(sysId, sql, "insert", orgId, deptId);
		}
	}

	/**
	 * 表单数据更新方法
	 *
	 * @param json
	 * @param sysId
	 * @param tableName
	 * @param nodeName
	 * @param nodeId
	 */
	@Override
	public void updateFormData(String json, String sysId, String tableName, String nodeName, String nodeId, String id, String orgId, String deptId) throws Exception {
		tableName = tableName.toUpperCase();
		String sql = "UPDATE " + tableName + " SET ";
		if (json != null) {
			JSONArray ja = JSONArray.fromObject(json);
			for (int i = 0; i < ja.size(); i++) {
				JSONObject jj = JSONObject.fromObject(ja.get(i));
				String name = jj.getString("name");
				String value = jj.getString("value");
				String type = getColType(tableName, name, sysId, nodeId, orgId);// 获取该字段类型
				if (type.equals("string")) {
					sql = sql + name + "='" + value + "',";
				} else if (type.equals("integer")) {
					if (!"".equals(value)) {
						sql = sql + name + "=" + value + ",";
					}
				} else if (type.equals("date")) {
					sql = sql + name + "= TO_DATE('" + value + "','yyyy-MM-dd HH24:mi:ss'),";
				} else if (type.equals("float")) {
					if (!"".equals(value)) {
						sql = sql + name + "=" + value + ",";
					}
				}
			}
			sql = sql.substring(0, sql.length() - 1);
			sql = sql + " where ID = '" + id + "'";
			// JDBC实现
			executeJdbc(sysId, sql, "update", orgId, deptId);
		}
	}

	/**
	 * 表单数据删除方法
	 *
	 * @param dataid
	 * @param tableName
	 */
	@Override
	public void deleteFormDataById(String dataid, String tableName, String sysId, String orgId, String deptId) throws Exception {
		String sql = "DELETE FROM " + tableName.toUpperCase() + " WHERE ID = '" + dataid + "'";
		// jdbc实现
		executeJdbc(sysId, sql, "delete", orgId, deptId);
	}

	/**
	 * 通过SYSID获取数据库用户名密码
	 *
	 * @param sysId
	 * @return
	 */
	public List<String> getDbInfoBySysId(String sysId) {
		List<String> info = new ArrayList<String>();
		String sql = "SELECT T.SYS_DB_USER,T.SYS_DB_PWD FROM CBB_SYS_INFO T WHERE T.ID = '" + sysId + "'";
		List<Object[]> list = hibernateDao.findBySQL(sql);
		if (list.size() != 0) {
			Object[] obj = list.get(0);
			String dbUser = String.valueOf(obj[0]);
			String dbPwd = String.valueOf(obj[1]);
			info.add(dbUser);
			info.add(dbPwd);
		}
		return info;
	}

	/**
	 * 用JDBC执行
	 *
	 * @param sysId
	 * @param sql
	 */
	public void executeJdbc(String sysId, String sql, String type, String orgId, String deptId) throws Exception {
		// 连接池
		DBConnectionCustomManager connectionMan = null;
		String poolName = orgId + "_" + sysId;
		Connection conn = null;
		Statement statement = null;
		try {
			// 实例化连接池
			connectionMan = DBConnectionCustomManager.getInstance(poolName);
			// 获取连接
			conn = connectionMan.getConnection(poolName);// 根据连接池名称从连接池中获取连接
			statement = conn.createStatement();
			if (type.equals("insert")) {
				statement.execute(sql);
				SysLogUtil.log("档案业务模块", "新增记录", OpType.insert, OpResult.success, LogBaseFactory.getLogBase());
			} else if (type.equals("update")) {
				statement.executeUpdate(sql);
				SysLogUtil.log("档案业务模块", "更新记录", OpType.update, OpResult.success, LogBaseFactory.getLogBase());
			} else if (type.equals("delete")) {
				statement.executeUpdate(sql);
				SysLogUtil.log("档案业务模块", "删除记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (statement != null) {
				try {
					statement.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			if (conn != null) {
				try {
					connectionMan.deleteConnection(poolName, conn);// 释放，但并未断开连接
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}

	/**
	 * 根据tabNodeId获取formId
	 *
	 * @author 朱锋
	 * @param sysId
	 * @param sql
	 * @param type
	 *            void
	 * @throws
	 */
	@Override
	public String getFormIdByTableNodeId(String tableNodeId) {
		String formId = "";
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.FORM_ID FROM CBB_TAB_FORM_NODE T WHERE T.TAB_NODE_ID = '" + tableNodeId + "'");
		List<Object> list = hibernateDao.findBySQL(sbSql.toString());
		if (list.size() != 0) {
			formId = String.valueOf(list.get(0));
		}
		return formId;
	}

	/**
	 * 根据tabNodeId获取formId
	 * @author 唐坤
	 * @param tableNodeId,archiveStatus
	 * @return     String
	 * @throws
	 */
	@Override
	public String getFormIdByTableNodeId(String tableNodeId, String archiveStatus) {
		String formId = "";
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.FORM_ID FROM CBB_TAB_FORM_NODE T WHERE T.TAB_NODE_ID = '" + tableNodeId + "' AND T.ARCHIVE_STATUS = '" + archiveStatus + "'");
		List<Object> list = hibernateDao.findBySQL(sbSql.toString());
		if (list.size() != 0) {
			formId = String.valueOf(list.get(0));
		}
		return formId;
	}

	/**
	 * 根据formId和字段ID判断是否存在表单配置信息
	 * @author 郭亮
	 * @param formId
	 * @param colId
	 * @return Y：有配置，N：无配置
	 * @throws Exception boolean
	 */
	@Override
	public boolean getformConfigByFormIdAndColId(String formId, String colId) throws Exception {
		boolean hasConfig = true;
		String sql = "SELECT COUNT(*) FROM CBB_TAB_FORM_CONFIG T WHERE T.FORM_ID = '" + formId + "' AND T.COLUMN_ID = '" + colId + "'";
		List<BigDecimal> list = this.hibernateDao.findBySQL(sql);
		if (null == list || list.size() == 0 || String.valueOf(list.get(0)).equals("0")) {
			hasConfig = false;
		}
		return hasConfig;
	}

	/**
	 * 获取templetId
	 *
	 * @author 朱锋
	 * @param orgId
	 * @param sysId
	 * @return String
	 * @throws
	 */
	public String getTempletId(String orgId, String sysId) {
		StringBuffer sbSqlTemplet = new StringBuffer();
		sbSqlTemplet.append("SELECT T.ID\n");
		sbSqlTemplet.append("  FROM CBB_TEMPLET_INFO T\n");
		sbSqlTemplet.append(" WHERE T.TEMP_TYPE = 'S'\n");
		sbSqlTemplet.append("   AND T.SYS_ID = '" + sysId.toUpperCase() + "'\n");
		sbSqlTemplet.append("   AND T.ORG_ID = '" + orgId + "'");
		List<Object> listTemplet = hibernateDao.findBySQL(sbSqlTemplet.toString());
		String templetId = "";
		if (listTemplet.size() != 0) {
			templetId = String.valueOf(listTemplet.get(0));
		}
		return templetId;
	}

	/**
	 * 根据表ID,节点ID判断表单是否存在
	 *
	 * @author 朱锋
	 * @param tableId
	 * @param nodeId
	 * @return
	 * @throws Exception
	 *             boolean
	 * @throws
	 */
	@Override
	public boolean checkHasForm(String tableId, String nodeId) throws Exception {
		boolean flag = false;
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT COUNT(*) AS COUNT \n");
		sbSql.append("  FROM CBB_TAB_FORM_NODE CTFN\n");
		sbSql.append("  LEFT JOIN CBB_TAB_NODE CTN\n");
		sbSql.append("    ON CTN.ID = CTFN.TAB_NODE_ID\n");
		sbSql.append(" WHERE CTN.TABLE_ID = '" + tableId + "'\n");
		sbSql.append("   AND CTN.NODE_ID = '" + nodeId + "'");
		List<Map<String, Object>> list = jdbcAvicit.queryForMap(sbSql.toString(), null);
		Map<String, Object> map = list.get(0);
		int num = Integer.parseInt(String.valueOf(map.get("COUNT")));
		if (num > 0) {
			flag = true;
		}
		return flag;
	}

	/**
	 * 根据表ID,节点ID判断表单是否存在
	 *
	 * @author 朱锋
	 * @param tableId
	 * @param nodeId
	 * @return
	 * @throws Exception
	 *             boolean
	 * @throws
	 */
	@Override
	public boolean checkHasForm(String tableId, String nodeId, String archiveStatus) throws Exception {
		boolean flag = false;
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT COUNT(*) AS COUNT \n");
		sbSql.append("  FROM CBB_TAB_FORM_NODE CTFN\n");
		sbSql.append("  LEFT JOIN CBB_TAB_NODE CTN\n");
		sbSql.append("    ON CTN.ID = CTFN.TAB_NODE_ID\n");
		sbSql.append(" WHERE CTN.TABLE_ID = '" + tableId + "'\n");
		sbSql.append("   AND CTN.NODE_ID = '" + nodeId + "'");
		sbSql.append("   AND CTFN.ARCHIVE_STATUS = '" + archiveStatus + "'");
		List<Map<String, Object>> list = jdbcAvicit.queryForMap(sbSql.toString(), null);
		Map<String, Object> map = list.get(0);
		int num = Integer.parseInt(String.valueOf(map.get("COUNT")));
		if (num > 0) {
			flag = true;
		}
		return flag;
	}

	/**
	 * 获取表单配置信息中的列信息
	 *
	 * @author 朱锋
	 * @param page
	 * @param parameter
	 * @param orgId
	 * @return
	 * @throws Exception
	 *             Page<Map<String,Object>>
	 * @throws
	 */
	@Override
	public Page<Map<String, Object>> getPageBillFormConfigList(Paging<CbbTempletCode> page, Map<String, Object> parameter) throws Exception {
		String nodeId = (String) parameter.get("nodeId");
		String tableId = (String) parameter.get("tableId");
		String sysId = (String) parameter.get("sysId");
		String archiveStatus = (String) parameter.get("archiveStatus");
		String formId = "";
		String tabNodeId = commTableManagerService.getCbbTabNodeId(sysId, nodeId, tableId);
		if (archiveStatus == null || "".equals(archiveStatus)) {
			// 获取表单ID
			formId = getFormIdByTableNodeId(tabNodeId);
		} else {
			formId = getFormIdByTableNodeId(tabNodeId, archiveStatus);
		}
		StringBuffer sbSql = new StringBuffer();

		sbSql.append("SELECT T.ID,CTC.COL_LABEL,CTC.COL_NAME,CTC.COL_TYPE,CTC.COL_LENGTH,CTC.REMARK,T.COL_IS_DETAIL,T.FORM_VERTICAL, T.FORM_HORIZONTAL,T.ATTRIBUTE_11 AS COL_ORDER,T.ATTRIBUTE_12,T.ATTRIBUTE_01 AS COL_IS_MUST,T.ATTRIBUTE_02 AS COL_IS_TAB_VISIBLE,T.ATTRIBUTE_03 AS COL_IS_VISIBLE\n");
		//SanXiaFiles update by huagjian ATTRIBUTE_04只读字段
		sbSql.append(" ,T.ATTRIBUTE_04\n ");
		sbSql.append("  FROM CBB_TAB_FORM_CONFIG T\n");
		sbSql.append(" INNER JOIN CBB_TAB_COLUMNS CTC\n");
		sbSql.append("    ON CTC.ID = T.COLUMN_ID\n");
		sbSql.append(" WHERE T.FORM_ID = '" + formId + "'\n");
		sbSql.append(" AND CTC.COL_IS_DISPLAY = 'Y'\n");
		// SanXiaFiles Create By Tangkun Start
		String inputWord = (String) parameter.get("inputWord");
		if (inputWord != null && !"".equals(inputWord)) {
			sbSql.append(" and (CTC.col_label like '%" + inputWord + "%'\n");
			sbSql.append(" or CTC.col_name like '%" + inputWord + "%'\n");
			sbSql.append(" or CTC.col_type like '%" + inputWord + "%')");
		}
		// SanXiaFiles Create By Tangkun End
		sbSql.append(" ORDER BY T.ATTRIBUTE_11,CTC.COL_NAME");
		Page<Map<String, Object>> pageBean = new Page<Map<String, Object>>(page.getPageNo(), page.getPageSize());
		jdbcAvicit.getDatesByPageForMap(pageBean, sbSql.toString(), parameter, null);
		return pageBean;
	}

	/**
	 * 获取模版库表单列信息
	 *
	 * @author 朱锋
	 * @param page
	 * @param parameter
	 * @param orgId
	 * @return
	 * @throws Exception
	 *             Page<Map<String,Object>>
	 * @throws
	 */
	@Override
	public Page<Map<String, Object>> getPageBillDbList(Paging<CbbTempletCode> page, Map<String, Object> parameter, String orgId) throws Exception {
		// String sysId = (String) parameter.get("sysId");
		String tableId = (String) parameter.get("tableId");
		// String templetId = getTempletId(orgId, sysId.toUpperCase());// templetId
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.ID,\n");
		sbSql.append("       T.COL_LABEL,\n");
		sbSql.append("       T.COL_NAME,\n");
		sbSql.append("       T.COL_TYPE,\n");
		sbSql.append("       T.COL_LENGTH,\n");
		sbSql.append("       T.REMARK,\n");
		sbSql.append("       T.COL_IS_DETAIL,\n");
		sbSql.append("       '1' AS FORM_VERTICAL,\n");
		sbSql.append("       '1' AS FORM_HORIZONTAL,\n");
		sbSql.append("       T.COL_ORDER,\n");
		sbSql.append("       T.ATTRIBUTE_11 as ATTRIBUTE_12,\n");
		sbSql.append("       T.COL_IS_MUST,\n");
		sbSql.append("       T.COL_IS_TAB_VISIBLE,\n");
		sbSql.append("       T.COL_IS_VISIBLE,\n");
		sbSql.append("       T.COL_IS_EDIT AS ATTRIBUTE_04 \n");//SanXiaFiles add by huangjian  编辑标识；Y-是，N-否；默认是
		sbSql.append("  FROM CBB_TAB_COLUMNS T\n");
		sbSql.append(" WHERE T.TABLE_ID = '" + tableId + "' AND T.COL_IS_DISPLAY = 'Y'\n");
		// SanXiaFiles Create By Tangkun Start
		String inputWord = (String) parameter.get("inputWord");
		if (inputWord != null && !"".equals(inputWord)) {
			sbSql.append(" and (t.col_label like '%" + inputWord + "%'\n");
			sbSql.append(" or t.col_name like '%" + inputWord + "%'\n");
			sbSql.append(" or t.col_type like '%" + inputWord + "%')");
		}
		// SanXiaFiles Create By Tangkun End
		sbSql.append(" ORDER BY T.COL_ORDER,T.COL_NAME");
		Page<Map<String, Object>> pageBean = new Page<Map<String, Object>>(page.getPageNo(), page.getPageSize());
		jdbcAvicit.getDatesByPageForMap(pageBean, sbSql.toString(), parameter, null);
		return pageBean;
	}

	/***
	 * 根据userId查找userName
	 *
	 * @return
	 */
	@Override
	public String getUserNameById(String id) throws Exception {
		String names = "";
		String[] ids = id.split(",");
		for (int i = 0; i < ids.length; i++) {
			String sql = "SELECT T.NAME FROM SYS_USER T WHERE T.ID = '" + ids[i] + "'";
			List<String> nameList = this.hibernateDao.findBySQL(sql);
			if (nameList != null && nameList.size() > 0) {
				names = names + "," + nameList.get(0);
			}
		}
		if (!"".equals(names)) {
			names = names.substring(1, names.length());
		}
		return names;
	}

	/***
	 * 根据deptId查找deptName
	 *
	 * @return
	 */
	@Override
	public String getDeptNameById(String id) throws Exception {
		String names = "";
		String[] ids = id.split(",");
		for (int i = 0; i < ids.length; i++) {
			String sql = "SELECT T.DEPT_NAME FROM SYS_DEPT_V T WHERE T.ID = '" + ids[i] + "'";
			List<String> nameList = this.hibernateDao.findBySQL(sql);
			if (nameList != null && nameList.size() > 0) {
				names = names + "," + nameList.get(0);
			}
		}
		if (!"".equals(names)) {
			names = names.substring(1, names.length());
		}
		return names;
	}

	/***
	 * 根据sysCode查找sysName
	 *
	 * @return
	 */
	@Override
	public String getSysNameByCode(String code) throws Exception {
		String sqlCustom = "SELECT T.SYS_NAME FROM CBB_SYS_INFO T WHERE T.ID = '" + code + "'";
		List<String> sysNameList = this.hibernateDao.findBySQL(sqlCustom);
		if (sysNameList != null && sysNameList.size() > 0) {
			return sysNameList.get(0);
		}
		return "";
	}

	/***
	 * 字符串字段配置为序列时的拼接字符串方法
	 *
	 * @author 郭亮
	 * @param data
	 *            选中行数据的值
	 * @param config
	 *            步长
	 * @return String
	 * @throws
	 */
	public String stringConfig(String data, String config) {
		String valueStr = "";
		if (null != data && !"".equals(data) && !"null".equals(data)) {
			char[] configChar = config.toCharArray();// 步长字符数组
			boolean configIsDigit = true;
			for (int i = 0; i < configChar.length; i++) {
				configIsDigit = Character.isDigit(configChar[i]);
				if (!configIsDigit) {
					break;// 步长不是数字，跳出循环
				}
			}
			if (!configIsDigit) { // 步长不是数字，步长 + 值
				valueStr = data + config;
			} else { // 步长是数字，进行运算
						// 截取出data字符串中的末尾数字位
				char[] dataChar = data.toCharArray();// 值字符数组
				boolean dataIsDigit = true;
				int dataIndex = dataChar.length;// 数字位标识
				for (int j = dataChar.length - 1; j >= 0; j--) {
					dataIsDigit = Character.isDigit(dataChar[j]);
					if (dataIsDigit) { // 是数字
						dataIndex = j;// 标识位更新
					} else {
						break;
					}
				}
				if (!dataIsDigit && dataIndex == dataChar.length) { // 值字符串末尾不包含数字
					valueStr = data + config;
				} else {
					// 截取值字符串的末尾数字位
					String dataNumStr = data.substring(dataIndex, data.length());
					int dataNum = Integer.parseInt(dataNumStr);
					int configNum = Integer.parseInt(config);
					int value = dataNum + configNum;
					valueStr = data.substring(0, dataIndex) + value;
				}
			}
		}
		return valueStr;
	}

	/***
	 * 获取组合项配置信息Map（用于应用页面判断取值）
	 *
	 * @author 郭亮
	 * @param sourceId
	 *            源字段Id
	 * @param tableId
	 *            本表Id
	 * @param recordId
	 *            数据行Id
	 * @return Map<String,Map<String,Map<String,String>>>
	 * @throws Exception
	 * @throws
	 */
	public Map<String, Map<String, Map<String, String>>> getConfigMap(String sourceId, String tableId, String recordId) throws Exception {
		Map<String, Map<String, Map<String, String>>> map = new HashMap<String, Map<String, Map<String, String>>>();
		// 根据源字段Id查找配置信息
		if (!"".equals(sourceId)) {
			String sql = "SELECT T.GROUP_ORDER,T.TARGET_TABLE_ID,T.TARGET_COLUMN_ID,T.TARGET_INPUT FROM CBB_TAB_COL_CONFIG_GROUP T WHERE T.SOURCE_COLUMN_ID = '" + sourceId + "'";
			List<Object[]> list = this.hibernateDao.findBySQL(sql);
			if (list.size() > 0) {
				for (int i = 0; i < list.size(); i++) {
					Map<String, Map<String, String>> orderMap = new HashMap<String, Map<String, String>>();
					Map<String, String> flagMap = new HashMap<String, String>();
					String order = (String) list.get(i)[0];
					String tgtTableId = (String) list.get(i)[1];
					String tgtColumnId = (String) list.get(i)[2];
					String tgtInput = (String) list.get(i)[3];
					String flag = ""; // 是否本表字段标示，Y：是；N：否
					String tgtColumnName = ""; // 组合字段名（当组合字段为本表字段时，tgtColumnName为字段名；当为外表字段时，tgtColumnName为某条数据的具体值）
					if (tableId.equals(tgtTableId)) { // 本表字段
						flag = "Y";
						// 通过tgtColumnId查找ColumnName
						tgtColumnName = this.getColumNameById(tgtColumnId);
					} else { // 非本表字段
						flag = "N";
						/*** 获取外表数据字段对应值 ***/
						// 获取表明，列名
						String tableName = this.getTableNameById(tgtColumnId);
						String colName = this.getColumNameById(tgtColumnId);
						// 根据表名，列名，数据行Id获取数据
						String dataSql = "SELECT T." + colName + " FROM " + tableName + " T WHERE T.ID = '" + recordId + "'";
						List<Object> dataList = this.hibernateDao.findBySQL(dataSql);
						if (dataList.size() > 0) {
							tgtColumnName = (String) dataList.get(0);
						}
					}
					flagMap.put(flag, tgtInput == null ? "" : tgtInput);
					orderMap.put(tgtColumnName, flagMap);
					map.put(order, orderMap);
				}
			}
		}
		return map;
	}

	/***
	 * 根据字段ID获取字段名
	 *
	 * @author 郭亮
	 * @return
	 * @throws Exception
	 *             String
	 * @throws
	 */
	public String getColumNameById(String id) throws Exception {
		String name = "";
		if (!"".equals(id)) {
			String sql = "SELECT T.COL_NAME FROM CBB_TAB_COLUMNS T WHERE T.ID = '" + id + "'";
			List<String> list = this.hibernateDao.findBySQL(sql);
			if (list.size() > 0) {
				name = list.get(0);
			}
		}
		return name;
	}

	/***
	 * 根据表Id获取表名
	 *
	 * @author 郭亮
	 * @param id
	 * @return
	 * @throws Exception
	 *             String
	 * @throws
	 */
	public String getTableNameById(String id) throws Exception {
		String tableName = "";
		if (!"".equals(id) && id != null && !"null".equals(id)) {
			String sql = "SELECT T.TABLE_NAME FROM CBB_TABLES T WHERE T.ID = '" + id + "'";
			List<Object> list = this.hibernateDao.findBySQL(sql);
			if (list.size() > 0) {
				tableName = (String) list.get(0);
			}
		}
		return tableName;
	}

	/***
	 * 获取表单管理树节点对应表数据个数
	 *
	 * @author 郭亮
	 * @param tableId
	 * @return
	 * @throws Exception
	 *             int
	 * @throws
	 */
	@Override
	public int getTableDataCount(String tableId) throws Exception {
		int count = 0;
		if (!"".equals(tableId) && null != tableId) {
			String sql = "SELECT COUNT(*) FROM CBB_TAB_COLUMNS T WHERE T.TABLE_ID = '" + tableId + "' AND T.COL_IS_DISPLAY = 'Y'";
			List<Object> list = this.hibernateDao.findBySQL(sql);
			if (list.size() > 0) {
				count = Integer.parseInt(String.valueOf(list.get(0)));
			}
		}
		return count;
	}

	/**
	 * 设置模版列数
	 * @author 郭亮
	 * @param param
	 * 				key1:nodeId,value:string 节点Id
	 * 				key2:tableId,value:string 表Id
	 * 				key3:columnNum,value:string 模版列数
	 * @throws Exception void
	 */
	@Override
	public void setModelColumn(Map<String, Object> param) throws Exception {
		String nodeId = (String) param.get("nodeId");
		String tableId = (String) param.get("tableId");
		int columnNum = Integer.parseInt((String) param.get("columnNum"));
		String archiveStatus = (String) param.get("archiveStatus");
		// 通过tableId和nodeId查找tab_node_Id
		String sql = "SELECT T.ID FROM CBB_TAB_NODE T WHERE T.TABLE_ID = '" + tableId + "' AND T.NODE_ID = '" + nodeId + "'";
		List<String> tabNodeIdList = this.hibernateDao.findBySQL(sql);
		if (tabNodeIdList.size() > 0) {
			// 根据tab_node_Id设置表单模版列数
			String tabNodeId = tabNodeIdList.get(0);
			String upSql ="";
			if(!StringUtils.isEmpty(archiveStatus)){
				upSql = "UPDATE CBB_TAB_FORM_NODE T SET T.ATTRIBUTE_11 =" + columnNum + " WHERE T.TAB_NODE_ID = '" + tabNodeId + "' AND T.ARCHIVE_STATUS= '"+ archiveStatus +"'";
			}else{
				upSql = "UPDATE CBB_TAB_FORM_NODE T SET T.ATTRIBUTE_11 =" + columnNum + " WHERE T.TAB_NODE_ID = '" + tabNodeId + "'";
			}
			this.jdbcAvicit.getJdbcTemplate().execute(upSql);
		}
	}

	/**
	 * 获取模板列数
	 * @author 郭亮
	 * @param param
	 * 				key1:nodeId,value:string 节点Id
	 * 				key2:tableId,value:string 表Id
	 * @return
	 * @throws Exception String
	 */
	@SuppressWarnings("rawtypes")
	@Override
	public String getModelColumn(Map<String, Object> param) throws Exception {
		String columnNum = "";
		String nodeId = (String) param.get("nodeId");
		String tableId = (String) param.get("tableId");
		// 通过tableId和nodeId查找tab_node_Id
		String sql = "SELECT T.ID FROM CBB_TAB_NODE T WHERE T.TABLE_ID = '" + tableId + "' AND T.NODE_ID = '" + nodeId + "'";
		List<String> tabNodeIdList = this.hibernateDao.findBySQL(sql);
		if (tabNodeIdList.size() > 0) {
			String tabNodeId = tabNodeIdList.get(0);
			String numSql = "SELECT T.ATTRIBUTE_11 FROM CBB_TAB_FORM_NODE T WHERE T.TAB_NODE_ID = '" + tabNodeId + "'";
			List list = this.hibernateDao.findBySQL(numSql);
			if (list.size() > 0) {
				columnNum = String.valueOf(list.get(0));
			}
		}
		return columnNum;
	}

	/**
	 * 根据formId删除表单配置信息
	 * @author 郭亮
	 * @param formId
	 * @throws Exception void
	 */
	@Override
	public void deleteFormDataByFormId(String formId) throws Exception {
		// 先删除子表记录再删除主表记录
		String formDataSql = "DELETE FROM CBB_TAB_FORM_CONFIG T WHERE T.FORM_ID = '" + formId + "'";
		String formNodeSql = "DELETE FROM CBB_TAB_FORM_NODE T WHERE T.FORM_ID = '" + formId + "'";
		String formSql = "DELETE FROM CBB_TAB_FORM T WHERE T.ID = '" + formId + "'";
		this.jdbc.getJdbcTemplate().execute(formDataSql);
		SysLogUtil.log("库结构定义模块", "删除表单配置记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
		this.jdbc.getJdbcTemplate().execute(formNodeSql);
		SysLogUtil.log("库结构定义模块", "删除表单配置记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
		this.jdbc.getJdbcTemplate().execute(formSql);
		SysLogUtil.log("库结构定义模块", "删除表单配置记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
	}

	/**
	 * @author
	 * 表单管理重置
	 * @param formId
	 * @throws Exception
	 */
	@Override
	public void resetFormDataByFormId(String sysId, String nodeId, String tableId) throws Exception {
		String tabNodeId = commTableManagerService.getCbbTabNodeId(sysId, nodeId, tableId);
		String formId = this.getFormIdByTableNodeId(tabNodeId);
		String formDataSql = "DELETE FROM CBB_TAB_FORM_CONFIG T WHERE T.FORM_ID = '" + formId + "' ";
		String formNodeSql = "DELETE FROM CBB_TAB_FORM_NODE T WHERE T.FORM_ID = '" + formId + "'";
		this.jdbc.getJdbcTemplate().execute(formDataSql);
		SysLogUtil.log("表单配置模块", "删除表单配置记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
		this.jdbc.getJdbcTemplate().execute(formNodeSql);
		SysLogUtil.log("表单配置模块", "删除表单配置记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
	}

	/**
	 * 表单管理重置
	 * @author 唐坤
	 * @param formId
	 * @throws Exception
	 */
	@Override
	public void resetFormDataByArchiveFormId(String sysId, String nodeId, String tableId, String archiveStatus) throws Exception {
		String tabNodeId = commTableManagerService.getCbbTabNodeId(sysId, nodeId, tableId);
		String formId = this.getFormIdByTableNodeId(tabNodeId,archiveStatus);
		String formDataSql = "DELETE FROM CBB_TAB_FORM_CONFIG T WHERE T.FORM_ID = '" + formId + "'";
		String formNodeSql = "DELETE FROM CBB_TAB_FORM_NODE T WHERE T.FORM_ID = '" + formId + "'";
		String formSql = "DELETE FROM CBB_TAB_FORM T WHERE T.ID = '" + formId + "'";
		this.jdbc.getJdbcTemplate().execute(formSql);//删除档案类型表单
		this.jdbc.getJdbcTemplate().execute(formDataSql);
		SysLogUtil.log("表单配置模块", "删除表单配置记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
		this.jdbc.getJdbcTemplate().execute(formNodeSql);
		SysLogUtil.log("表单配置模块", "删除表单配置记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());

	}
}
